package com.arron.ssm.exception;

import com.arron.ssm.vo.ResultObjVo;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @Classname GlobalExceptionHandler
 * @Date 2020/9/22 21:22
 * @Created by 刘
 */
@ControllerAdvice//告诉spring mvc它是一个全局的异常处理
public class GlobalExceptionHandler {


    @ExceptionHandler(RuntimeException.class)//指定方法处理的异常类
    @ResponseBody
    public ResultObjVo doHandleRunException(RuntimeException e){
        //在后台打印出异常信息
        e.printStackTrace();
        //返回给前端的信息
        return new ResultObjVo(444,e.getMessage().toString());
    }

}
